<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('财务账户列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>账户名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>账号：</label>
                                <input type="text" name="accountNo"/>
                            </li>
                            <li>
                                <label>银行名称：</label>
                                <input type="text" name="bankName"/>
                            </li>
                            <li>
                                <label>当前余额：</label>
                                <input type="text" name="balance"/>
                            </li>
                            <li>
                                <label>账户描述：</label>
                                <input type="text" name="description"/>
                            </li>
                            <li>
                                <label>创建时间：</label>
                                <input type="text" class="time-input" placeholder="请选择创建时间" name="createdAt"/>
                            </li>
                            <li>
                                <label>更新时间：</label>
                                <input type="text" class="time-input" placeholder="请选择更新时间" name="updatedAt"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="fin:account:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="fin:account:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="fin:account:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="fin:account:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="refreshTable()">
                    <i class="fa fa-refresh"></i> 刷新余额
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('fin:account:edit')}]];
        var removeFlag = [[${@permission.hasPermi('fin:account:remove')}]];
        var prefix = ctx + "fin/account";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "财务账户",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'name',
                    title: '账户名称'
                },
                {
                    field: 'accountNo',
                    title: '账号'
                },
                {
                    field: 'bankName',
                    title: '银行名称'
                },
                {
                    field: 'balance',
                    title: '当前余额'
                },
                {
                    field: 'description',
                    title: '账户描述'
                },
                {
                    field: 'status',
                    title: '状态'
                },
                {
                    field: 'createdAt',
                    title: '创建时间'
                },
                {
                    field: 'updatedAt',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="refreshBalance(\'' + row.id + '\')"><i class="fa fa-refresh"></i>刷新余额</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        // 刷新表格
        function refreshTable() {
            $.table.refresh();
        }
        
        // 刷新单个账户余额
        function refreshBalance(id) {
            $.ajax({
                url: prefix + "/refreshBalance/" + id,
                type: "get",
                dataType: "json",
                success: function(data) {
                    if (data.code == 0) {
                        $.modal.msgSuccess("余额刷新成功：" + data.data);
                        $.table.refresh();
                    } else {
                        $.modal.msgError(data.msg);
                    }
                },
                error: function() {
                    $.modal.msgError("余额刷新失败，请重试");
                }
            });
        }
    </script>
</body>
</html>